using System;
using Avanzis.QueryFramework;
using NUnit.Framework;

namespace Avanzis.QueryBuilder.NUnit.MsSql2000
{
    public class MsSql2000SelectClauseTest : SelectClauseTest
    {
        private Dialects previousDialect = Dialects.MSSql2005Dialect;

        [TestFixtureSetUp]
        public virtual void Setup()
        {
            previousDialect = QueryFrameworkConfiguration.Dialect;
            QueryFrameworkConfiguration.Dialect = Dialects.MSSql2000Dialect;
            QueryBuilder.QueryProcessor.ResetProcessor();
        }


        [TestFixtureTearDown()]
        public virtual void TearDown()
        {
            QueryFrameworkConfiguration.Dialect = previousDialect;
        }

        [Test]
        public override void SelectTopDistinct()
        {
            SelectClause select = new SelectClause();
            select.Fields.Add("CustomerId");
            select.SelectionType = SelectionTypes.Distinct;
            select.Limit = 10;
            Assert.AreEqual("SELECT DISTINCT TOP 10 CustomerId", select.ToString());
        }

        [Test]
        public override void SelectTop()
        {
            SelectClause select = new SelectClause();
            select.Fields.Add("CustomerId");
            select.Limit = 10;
            Assert.AreEqual(10, select.Limit);
            Assert.AreEqual("SELECT TOP 10 CustomerId", select.ToString());
        }

        [Test]
        [ExpectedException(typeof(InvalidOperationException))]
        public override void SelectEnableCalculateFoundRows()
        {
            SelectClause select = new SelectClause();
            select.Fields.Add("CustomerId");
            select.EnableCalculateFoundRows = true;

            string sql = select.ToString();
        }

    }
}
